<?php

namespace App\Exceptions;

class CustomGameException extends \Exception
{
    /**
     * 未达到领取条件
     */
    const NOT_FOUND_ROOM_GAME_CONFIG = 2001;

    /**
     * 发起游戏失败,launchGame
     */
    const LAUNCH_GAME_FIAL_ERROR = 2002;

    /**
     * 发起游戏失败,launchGame
     */
    const NOT_FOUND_ROOM_GAME_ERROR = 2003;

    /**
     * 保存游戏设置失败
     */
    const SAVE_GAME_CONF_FIAL_ERROR = 2004;

    /**
     * 发起游戏时，游戏已经变更
     */
    const SAVE_GAME_CHANGE_ERROR = 2005;

    /**
     * @var string[]
     * self::NOT_FOUND_ROOM_GAME_ERROR -- 游戏不可见或者不存在
     */
    public static $errorMsg = [
        self::NOT_FOUND_ROOM_GAME_CONFIG => '未找到房间游戏设置',
        self::LAUNCH_GAME_FIAL_ERROR => '发起游戏失败',
        self::NOT_FOUND_ROOM_GAME_ERROR => '游戏更新啦，请返回重新查看~',
        self::SAVE_GAME_CONF_FIAL_ERROR => '保存游戏设置失败',
        self::SAVE_GAME_CHANGE_ERROR => '游戏已更新，请返回重新查看~'
    ];

    /**
     * 根据错误码返回错误信息
     * @param $errorCode
     * @return string
     */
    public static function getErrorMsg($errorCode): string
    {
        if(isset(self::$errorMsg[$errorCode])){
            return self::$errorMsg[$errorCode];
        }else{
            return '请求错误，请稍后重试';
        }
    }
}
